package com.jah.picavue.client.model;

import java.util.ArrayList;

import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONValue;

public class Album {
	private String albumID = "";
	private String albumName = "";
	private String albumThumbURL = "";
	private ArrayList<Photo> albumPics = new ArrayList<Photo>();
	private int PhotosCount = 0;
	private boolean hasData = false;

	public Album() {};

	public Album(JSONValue entry) {
		setID(entry.isObject().get("gphoto$id").isObject().get("$t").isString().stringValue());
        setName(entry.isObject().get("gphoto$name").isObject().get("$t").isString().stringValue());
        setThumb(entry.isObject().get("media$group").isObject().get("media$thumbnail").isArray().get(0).isObject().get("url").isString().stringValue());
	};

	public void setID(String id) {
		this.albumID = id;
	}

	public void setName(String name) {
		this.albumName = name;
	}

	public void setThumb(String thumb) {
		this.albumThumbURL = thumb;
	}

	public void addPhotos(JSONArray json_array) {
		for (int i = 0; i < json_array.size(); ++i) {
			Photo photo = new Photo(json_array.get(i));
			this.albumPics.add(photo);
		    this.PhotosCount++;
		}
		hasData = true;
	}

	public String getID() {
		return this.albumID;
	}

	public String getName() {
		return this.albumName;
	}

	public String getThumb() {
		return this.albumThumbURL;
	}

	public ArrayList<Photo> getPhotos() {
		return this.albumPics;
	}

	public int numPhotos() {
		return this.PhotosCount;
	}

	public boolean hasPhotoData() {
		return hasData;
	}

}
